package com.example.demo.sharding;

import com.alibaba.druid.util.StringUtils;
import com.mybatisflex.core.audit.http.HashUtil;
import com.mybatisflex.core.dialect.OperateType;
import com.mybatisflex.core.table.DynamicTableProcessor;

/**
 * @author Administrator
 */
public class TableShardingStrategy implements DynamicTableProcessor {

    /**
     * 分表字段
     */
    public static ThreadLocal<Long> shardTableLocal = new ThreadLocal<>();

    /**
     * 表的数量
     */
    private static final int TABLE_COUNT = 2;

    @Override
    public String process(String tableName) {
        long index = shardTableLocal.get() % TABLE_COUNT;
        shardTableLocal.remove();

        return tableName+"_0"+(index+1);
    }
}
